package org.example;

import javax.swing.*;

public class CodeRebirthGame extends JFrame {
    private GameState currentState;
    private PlayerData playerData;
    private CodeChallengeManager challengeManager;
    private MainDeityDetectionSystem detectionSystem;
    private ResourceManager resourceManager;
    private StoryManager storyManager;

    public static final int WIDTH = 1024;
    public static final int HEIGHT = 768;

    public CodeRebirthGame() {
        setTitle("Code Rebirth: 系统觉醒");
        setSize(WIDTH, HEIGHT);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(false);

        // 初始化系统
        resourceManager = ResourceManager.getInstance();
        playerData = new PlayerData();  // 移除了参数，使用默认构造
        challengeManager = new CodeChallengeManager(this);  // 需要传入当前游戏实例
        detectionSystem = new MainDeityDetectionSystem(this);
        storyManager = new StoryManager();

        // 设置初始状态
        changeState(new MainMenuState(this) {
            @Override
            public void render() {

            }
        });
    }

    public void changeState(GameState newState) {
        if(currentState != null) {
            currentState.exit();
        }
        currentState = newState;
        currentState.enter();
    }

    // Getter方法
    public PlayerData getPlayerData() { return playerData; }
    public CodeChallengeManager getChallengeManager() { return challengeManager; }
    public MainDeityDetectionSystem getDetectionSystem() { return detectionSystem; }
    public ResourceManager getResourceManager() { return resourceManager; }
    public StoryManager getStoryManager() { return storyManager; }

    public GameState getCurrentState() {
        return currentState;
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            CodeRebirthGame game = new CodeRebirthGame();
            game.setVisible(true);
        });
    }
}
